// EventEmitter.js
var subscribers = [];

function Event(eventName, callBack) {
    this.eventName = eventName;
    this.callBack = callBack;
}

var EventEmitter = {
    addListener: (eventName, callBack) => {
        let event = new Event(eventName, callBack);
        subscribers.push(event);
        return event;
    },

    dispatch: (eventName, param) => {
        subscribers.forEach(function (event) {
            if (event.eventName === eventName) {
                event.callBack && event.callBack(param);
            }
        });
    }
}

module.exports = EventEmitter;